﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace SerialPortExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string portName = "COM1";
            int baudRate = 38400;
            Parity parity = Parity.None;
            int dataBits = 8;
            StopBits stopbits = StopBits.One;

            SerialPort myPort = new SerialPort(portName, baudRate, parity, dataBits, stopbits);
            myPort.Open();

            int totalByte = myPort.BytesToRead;
            int readed = 0;
            byte[] buffer = new byte[totalByte];
            while (readed < totalByte)
            {
                int length = myPort.Read(buffer, readed, totalByte - readed);
                readed += length;
            }

            myPort.Write(buffer, 0, buffer.Length);

            string text = "あいし";
            text = new String(text.ToCharArray(
            myPort.Write(text);

            Console.ReadLine();
        }
    }
}
